package pam.web;

import java.util.Enumeration;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

class PlainRequestParser implements IRequestParser {

	public Parameters parse(HttpServletRequest req) throws WebException {

		Parameters map = null;

		HashMap parameters = new HashMap();

		for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
			String key = (String) e.nextElement();
			String[] values = req.getParameterValues(key);

			if (values == null) {
				parameters.put(key, values);
				continue;
			}

			int len = values.length;
			String[] tmpValues = new String[len];
			for (int i = 0; i < len; i++) {
				String value = values[i];
				tmpValues[i] = value;
			}
			parameters.put(key, tmpValues);
		}
		map = new Parameters(parameters);

		return map;
	}
}
